<template>
	<view class="card-page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view slot="top">
				<view class="tab-list">
					<view :class="tabsIndex==index?'tab-item active':'tab-item'" v-for="(item,index) in tabsList"
						:key="index" @click="tabsChange(index)">{{item.name}}</view>
				</view>
			</view>
			<view class="card-list">
				<view class="card-item" v-for="(item,index) in dataList" :key="index"
					@click="$Tips('/pages/merchant/couponDetail?coupon_id='+item.coupon_id+'&page=detail')">
					<view :class="item.is_used==1?'item-left active':'item-left'">
						<view :class="item.is_used==1?'coupon-top top-active':'coupon-top'" v-if="!item.merchant_user_id">平台通用</view>
						<view :class="item.is_used==1?'coupon-top top-active':'coupon-top'" v-else>此商家可用</view>
						<view class="coupon-money">
							<text class=" coupon-unit">¥</text>{{item.number}}
						</view>
						<view class="coupon-rule" v-if="item.money!=0">满{{item.money}}可用</view>
						<view class="coupon-rule" v-else>无门槛</view>
					</view>
					<view class="item-center">
						<view class="item-title">{{item.coupon_name}}</view>
						<view class="item-type">有效期至:{{item.expire_time}}</view>
						<view class="item-time">使用说明<text v-if="item.merchant_user_id">:{{item.merchant_name}}专用</text>
						</view>
					</view>
					<view class="item-right ">
						<view class="use" v-if="item.is_used==1"
							@click.stop="$Tips({title:''},{tab:1,url:'/pages/index/index'})">使用</view>
						<image src="../../static/mine/icon_use.png" class="expired" v-if="item.is_used==2"></image>
						<image src="../../static/mine/icon_expired.png" class="expired" v-if="item.is_used==3">
					</view>

				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsList: [{
					name: '未使用',
					status: '1',
				}, {
					name: '已使用',
					status: '2',
				}, {
					name: '已过期',
					status: '3',
				}],
				tabsIndex: 0,
				dataList: [],
			}
		},
		methods: {
			tabsChange(index) {
				this.tabsIndex = index
				this.refreshList()
			},
			refreshList() {
				this.$refs.paging.scrollToTop()
				this.$refs.paging.refresh();
			},
			queryList(pageNo, pageSize) {
				this.$Api.user.getMyCoupon({
					page: pageNo,
					limit: pageSize,
					is_used: this.tabsList[this.tabsIndex].status
				}).then(res => {
					this.$refs.paging.complete(res.data.list);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card-page {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F8;

		.tab-list {
			min-height: 86rpx;
			margin: 20rpx 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.tab-item {
				text-align: center;
				width: 216rpx;
				height: 88rpx;
				line-height: 88rpx;
				box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
				border-radius: 200rpx;
				font-weight: bold;
				font-size: 32rpx;
			}

			.active {
				background: #A3C616;
				color: #ffffff;
			}
		}

		.card-list {
			margin: 0rpx 30rpx;

			.card-item {
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				box-sizing: border-box;
				box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1), inset 0rpx 2rpx 2rpx 0rpx #FFFFFF;
				border-radius: 28rpx;
				background: #ffffff;
				overflow: hidden;

				.item-left {
					width: 180rpx;
					height: 228rpx;
					margin-right: 20rpx;
					background-color: #d6d6d6;
					color: #FFFFFF;

					.coupon-top {
						font-weight: 400;
						font-size: 14px;
						line-height: 21px;
						text-align: center;
						padding: 10rpx 0;
						border-radius: 14px 0px 0px 0px;
					}
					.top-active{
						background: linear-gradient(90deg, #FFE2E2 0%, #FFF3F3 100%);
					}

					.coupon-money {
						font-weight: bold;
						font-size: 26px;
						line-height: 39px;
						text-align: center;
						margin-top: 12rpx;

						.coupon-unit {
							font-weight: bold;
							font-size: 26rpx;
							text-align: center;
						}
					}

					.coupon-rule {
						margin-top: 12rpx;
						font-weight: 400;
						font-size: 14px;
						line-height: 21px;
						text-align: center;
					}
				}

				.active {
					background-color: #fff3f3;
					color: #FF1E00;
				}

				.item-center {
					flex: 1;
					height: 228rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;

					.item-title {
						font-weight: bold;
						font-size: 32rpx;
					}

					.item-type {
						font-size: 26rpx;
						color: #565656;
						margin-top: 16rpx;
					}

					.item-time {
						font-size: 26rpx;
						color: #565656;
						margin-top: 16rpx;
					}
				}

				.item-right {
					margin-right: 20rpx;

					.use {
						width: 112rpx;
						height: 52rpx;
						background: linear-gradient(270deg, #FE4369 0%, #FE746D 100%);
						border-radius: 100rpx;
						font-size: 24rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 52rpx;
					}

					.expired {
						width: 152rpx;
						height: 152rpx;
					}
				}
			}
		}
	}
</style>